package com.shujia.day15.gc;

public abstract class Factory {
    public abstract Animal getAnimal(String name);
}


class CatFactory extends Factory{
    String animalName;

    public CatFactory() {
        this.animalName = "cat";
    }

    // TODO 该方法仅做其他方法的调用
    @Override
    public Animal getAnimal(String name) {
        return getCatAnimal(name);
    }

    // TODO 在该方法中可以控制对猫类的创建
    public Cat getCatAnimal(String name){
        return new Cat(name);
    }
}

class DogFactory extends Factory{
    String animalName;

    public DogFactory() {
        this.animalName = "dog";
    }

    // TODO 该方法仅做其他方法的调用
    @Override
    public Animal getAnimal(String name) {
        return getDogAnimal(name);
    }

    // TODO 在该方法中可以控制对猫类的创建
    public Dog getDogAnimal(String name){
        return new Dog(name);
    }
}

abstract class Animal {
    public abstract void eat();
}

class Cat extends Animal {
    String name;

    public Cat(String name) {
        this.name = name;
    }

    @Override
    public void eat() {
        System.out.println("🐱爱吃🐟");
    }
}

class Dog extends  Animal {
    String name;

    public Dog() {
    }

    public Dog(String name) {
        this.name = name;
    }

    @Override
    public void eat() {
        System.out.println("🐕爱吃骨头");
    }
}